#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int a[N],f[N],mx=-1,n;
void dfs(int k){
    if(k>n){
        int _red=0,_blue=0,sum=0;
        for(int i=1;i<=n;++i){
            if(f[i]==1){
                if(a[i]==a[_red]) sum+=a[i];
                _red=i;
            }
            if(f[i]==2){
                if(a[i]==a[_blue]) sum+=a[i];
                _blue=i;
            }
        }
        mx=max(mx,sum);
        return;
    }
    f[k]=1,dfs(k+1);
    f[k]=2,dfs(k+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;++i){
            cin>>a[i];
        }
        dfs(1);
        cout<<mx<<endl;
        mx=-1;
    }
}
